<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:include page="inc.jsp" />   
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<c:set var="ctx" value="${pageContext.request.contextPath }" />
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			$(function(){
				createMenu();
			});
		
			function clickMenu(obj){
				var a = $(obj).find('a');
				var title = a.html();
				var src = a.attr('src');
				var icon = a.attr('icon');
				addTab(title,src,icon);
			}
			
			function addTab(title,src,icon){
				//获取选项卡对象
				var t = $('#tt');
				if(t.tabs('exists',title)){
					t.tabs('select',title);
				}else{	
					//新增一个选项卡
					t.tabs('add',{
						title:title,
						closable:true,
						selected:true,
						iconCls:icon,
						content:'<iframe src="'+src+'" scrolling="no" frameborder="0" style="width: 100%;height: 99%;"></iframe>'
					});
				}
			}
			
			function activeMenu(title){
				//移除选中的样式				
				$('.menuson li.active').removeClass('active');
				//获取所有的li
				$('.menuson').each(function(i,ul){
					var lis = $(this).find('li');
					$.each(lis, function(j,li) {
						var html = $(this).find('a').html();
						if(html==title){
							//获取分类的面板
							$('#ea').accordion('select',i);
							//添加样式
							$(this).addClass('active');
							return false;
						}
					});
				})
				
			}
			
			function createMenu(){
				$.ajax({
					//url:'${ctx}/data/menu.json',
					url:'${ctx}/rc/findMenuByRid/-1.coc',
					dataType:'json',
					async:false,//异步改为同步请求
					success:function(r){
						r = $.parseJSON(r);//把json字符串转换为json对象
						for(var i=0;i<r.length;i++){
							var os = r[i];
							var title = os.name;
							var icon = os.icon;
							var href = os.href;
							var cs = os.childs;
							var str = '<div title="'+title+'" data-options="'+
										 'iconCls:\''+icon+'\''+
												'" style="overflow: auto;padding: 0px;background: #f0f9fd;">'+
												'<ul class="menuson">';
							for(var j=0;j<cs.length;j++){
								var ms = cs[j];
								title = ms.name;
								icon = ms.icon;
								href = ms.href;
								str+='<li onclick="clickMenu(this)">'+
										'<cite></cite>'+
										'<a href="#" src="${ctx}/'+href+'.coc" icon="'+icon+'">'+title+'</a>'+
									 '</li>';
							}
							
							str +="</ul></div>"
							$("#ea").append(str); 
							 
						}
					}
				});
				
			}
			
		</script>
		
		<div class="lefttop">
			<span></span>系统菜单
		</div>
		<div id="ea" class="easyui-accordion" data-options="
			fit:false,
			border:false
			">
			
		</div>
	</body>
</html>

    